﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
</head>
<body>
    <table id="appList" class="easyui-datagrid" title="应用管理" singleselect="true"
           data-options="rownumbers:true,pagination:true,fit:true,toolbar:'#operateDiv',
           toolbar:'#appTool',sortName: 'Unid',sortOrder: 'asc'">
        <thead>
            <tr>
                <th data-options="field:'AppId',width:20">AppId</th>
                <th data-options="field:'AppName',width:30">AppName</th>
                <th data-options="field:'AppStatus',width:20">AppStatus</th>
                <th data-options="field:'Memo',width:30">Memo</th>
            </tr>
        </thead>
    </table>

    <div id="appTool">
        <a class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="newMol()">新增</a>
        <a class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editMol()">编辑/查看</a>
        <a class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="delMol()">删除</a>
    </div>

    <div id="appDetail" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
         closed="true" buttons="#detailBtn">
        <form id="appFarm" method="post" novalidate>
            <table cellpadding="5">
                <tr>
                    <td>AppId:</td>
                    <td><input name="AppId" class="easyui-validatebox" required="true"></td>
                </tr>
                <tr>
                    <td>AppName:</td>
                    <td><input name="AppName" class="easyui-validatebox" required="true"></td>
                </tr>
                <tr>
                    <td>AppStatus:</td>
                    <td>
                        <select class="easyui-combobox" name="AppStatus" id="AppStatus">
                            <option value="1" selected="selected">在用</option>
                            <option value="-1">停用</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>Memo:</td>
                    <td><input name="Memo" class="easyui-validatebox"></td>
                </tr>
            </table>
        </form>
    </div>

    <div id="detailBtn">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="saveMol()">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel"
           onclick="javascript: $('#appDetail').dialog('close')">取消</a>
    </div>

    <script type="text/javascript">
        var status;
        var selectUnid;
        $(function () {
            $('#appList').datagrid({
                url: '/AuthApp/GetAuthApp',
                methord: 'post',
                fitColumns: true,
                idField: 'Unid',
                rownumbers: true
            })
        })
        function newMol() {
            $('#appDetail').dialog('open').dialog('setTitle', '新增应用');
            $('#appFarm').form('clear');
            $("#AppStatus").combobox('setValue', 1);
            status = true;
        }
        function editMol() {
            var row = $('#appList').datagrid('getSelected');
            if (row) {
                $('#appDetail').dialog('open').dialog('setTitle', '编辑/查看应用');
                $('#appFarm').form('load', row);
                status = false;
                selectUnid = row.Unid;
            }
            else {
                $.messager.alert('操作提示', '请选中需要编辑/查看的数据！', 'info');
            }
        }
        function saveMol() {
            var urlStr;
            if (status) {
                urlStr = '/AuthApp/CreateAuthApp';
            }
            else {
                urlStr = '/AuthApp/EditAuthApp?unid=' + selectUnid;
            }
            $('#appFarm').form('submit', {
                url: urlStr,
                onSubmit: function () {
                    return $(this).form('validate');
                },
                success: function (result) {
                    $('#appDetail').dialog('close');
                    $('#appList').datagrid('reload');
                }
            });
        }
        function delMol() {
            var row = $('#appList').datagrid('getSelected');
            if (row) {
                $.messager.confirm('警告', '确定要删除选中的数据?', function (choose) {
                    if (choose) {
                        $.post('/AuthApp/DeleteAuthApp?unid=' + row.Unid,
                            function (result) {
                                $('#appList').datagrid('reload');
                            }, 'json');
                    }
                });
            }
            else {
                $.messager.alert('操作提示', '请选中需要删除的数据！', 'info');
            }
        }
    </script>
</body>
</html>
